import { Component, OnInit, OnDestroy } from '@angular/core'
import { ActivatedRoute } from '@angular/router'

import { ERoleType, ECustomAcl } from '@shared/enums'
import { DataService } from '@shared/services/data.service'
import { IAamsLevel } from '@shared/components/aams-select/aams-select.interface'
import { CustomACLService } from '@shared/services/acl.service'

@Component({
  selector: 'app-store-detail-tab-users',
  templateUrl: './tab-users.component.html',
  styleUrls: ['../../../../shared/styles/table.less'],
})
export class StoreDetailTabUsersComponent implements OnInit {
  params: {[code: string]: string}
  storeRole = ERoleType.Store
  insCode: string

  constructor(
    public route: ActivatedRoute,
    private dataService: DataService,
    private customACLService: CustomACLService,
  ) {}

  ngOnInit() {
    this.getIntStoreCode()
    this.getInsCode()
  }

  getIntStoreCode() {
    /** 审核中使用 */
    let intStoreCode = this.dataService.intStoreCode
    if (!!intStoreCode) {
      this.params = {
        intStoreCode
      }
      return
    }

    /** 门店中使用 */
    this.route.parent.params.subscribe(params => {
      intStoreCode = params['id']
      this.params = {
        intStoreCode,
        userType: IAamsLevel.Store
      }
    })
  }

  getInsCode() {
    this.insCode = this.dataService.insCode
  }
}
